package com.whq.thrift.api.web.admin.db.admin;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

public interface UserInfoMapper {
	@Select("select * from t_user_info where email=#{email}")
	@Results(value={
			@Result(property="email",column="email"),
			@Result(property="status",column="status"),
			@Result(property="createTime",column="create_time"),
			@Result(property="updateTime",column="update_time")
	})
	public UserInfo getSelectRecrodByKey(@Param("email") String email);
	
	@SelectProvider(method="getSelectRecordSql",type=UserInfoSqlProvider.class)
	@Results(value={
			@Result(property="email",column="email"),
			@Result(property="status",column="status"),
			@Result(property="createTime",column="create_time"),
			@Result(property="updateTime",column="update_time")
	})
	public List<UserInfo> getSelectRecrodByMap(Map<String, Object> whereParams);
	
	@Insert("INSERT INTO t_user_info " + " (email, status, create_time, update_time)"
			+ " VALUES " + " ( #{email}, #{status}, #{createTime}, #{updateTime})")
	@Options(useGeneratedKeys = true, keyProperty = "email")
	public void addRecord(UserInfo record);
	
	@SelectProvider(type = UserInfoSqlProvider.class, method = "getSelectCountSql")
	public int findRecordsCount(Map<String, Object> whereParams);

	@UpdateProvider(type = UserInfoSqlProvider.class, method = "getUpdateSql")
	public void updRecord(UserInfo record);

	@Delete("delete from t_user_info where email=#{email}")
	public void delRecord(@Param("email") String email);
	
	@Select("select * from t_permission_uri")
	@Results(value={
			@Result(property="permissionId",column="permission_id"),
			@Result(property="uri",column="uri"),
			@Result(property="module",column="module"),
			@Result(property="comment",column="comment"),
			@Result(property="createTime",column="create_time"),
			@Result(property="updateTime",column="update_time")
	})
	public List<PermissionUri> findPermissionUriByMap();
	
	@Select("select * from t_user_permission where email=#{email}")
	@Results(value={
			@Result(property="id",column="id"),
			@Result(property="email",column="email"),
			@Result(property="permissionId",column="permission_id")
	})
	public List<UserMermission> findUserMermissionByEmail(String email);
	
	@Delete("delete from t_user_permission where email=#{email}")
	public void delUserPermission(String email);
	
	@Insert("INSERT INTO t_user_permission (email, permission_id) VALUES( #{email}, #{permissionId})")
	public void addUserPermission(UserMermission record);
}
